package com.blood.modules.system.controller;

import com.blood.core.annotation.JwtIgnore;
import com.blood.core.resp.GlobalResultStatus;
import com.blood.core.resp.ResponseResult;
import com.blood.core.resp.TokenResp;
import com.blood.core.util.http.RequestTheadUtils;
import com.blood.modules.system.dto.req.SysUserLoginReq;
import com.blood.modules.system.dto.resp.SysMenuAuthorityResp;
import com.blood.modules.system.service.ISysRoleAuthorityService;
import com.blood.modules.system.service.ISysUserService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author daoren
 */
@Api(value = "权限认证", tags = "权限认证")
@RestController
@ApiSort(1)
@RequestMapping("/sys/auth")
public class SysAuthController {
    /**
     * 系统用户表服务.
     */
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysRoleAuthorityService sysRoleAuthorityService;

    /**
     * 用户登录新
     *
     * @param req
     * @return 返回token信息
     */
    @ApiOperation(value = "用户登录")
    @PostMapping(value = "/login")
    @JwtIgnore
    public ResponseResult<TokenResp> login(@RequestBody @Validated SysUserLoginReq req) {
        return sysUserService.accountLogin(req);
    }

    /**
     * 获取用户菜单权限
     *
     * @return 菜单
     */
    @ApiOperation(value = "获取用户菜单权限")
    @GetMapping(value = "/getMenu")
    public ResponseResult<SysMenuAuthorityResp> getRole() {
        SysMenuAuthorityResp resp = new SysMenuAuthorityResp();
        resp.setRole(RequestTheadUtils.getRole());
        return GlobalResultStatus.SUCCESS.toResult().response(resp);
    }

}
